<script type="text/javascript">
$(function(){
	var pg = App.batch.appMonitor.ui, pp = pg.params,
		nv = pg.children('.navi');
	
	nv.seek('title').text(pp.addr + '节点');
	nv.seek('back').click(function(){
		pg.callback();
	});
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols: [{
			field: 'catalog', title: '所属系统', width: 168
		},{
			field: 'code', title: '批量名称', width: 168
		},{
			field: 'entry', title: '入口', width: 168
		},{
			field: 'startTime', title: '开始时间', width: 168
		},{
			field: 'status', title: '状态', width: 78,
			render: function(r) {
				return Cache.batch.execution.status[r.status];
			}
		},{
			field: 'endTime', title: '结束时间', width: 168
		},{
			field: 'addr', title: '执行机器IP', width: 168
		},{
			field: 'error', title: '错误信息', width: 168
		},{
			field: 'no', title: '执行次数', width: 168
		},{
			field: 'type', title: '执行类型', width: 168,
			render: function(r) {
				return Cache.batch.execution.type[r.type];
			}
		},{
			field: 'params', title: '参数', width: 168
		},{
			field: 'step', title: '当前步骤', width: 168
		},{
			field: 'id', title : '操作', width: 120,
			render: function(r, tr, gd) {
				var p = $('<div></div>'), v = r.status,
					st = '<span class="a"></span>';
				if ($.inArray(v, [0,1,2])) {
					$(st).click(function(){
						mac.confirm('确定要 取消 这一任务的执行吗？', function(){
							$.post(App.ctx + '/execution/cancel.do', {
								id: r.id
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append('取消').appendTo(p);
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/app/stat.do',
			params: {
				addr: pp.addr, pageNo: 1, pageSize: 20
			},
			autoLoad: false
		},
		pagerLength: 10
	});
	
	var hd = pg.children('.head');
	hd.seek('key').keydown(function(e){
		if (e.keyCode == 13) {
			gd.load({ key: $(this).val() });
		}
	});
	hd.seek('find').click(function(){
		gd.load({ key: pg.seek('key').val() });
	});
	hd.seek('refresh').click(function(){
		gd.load();
	});

	function adjust(){
		var h = pg.parent().height();
		pg.height(h - 8);
		gd.parent().height(h - 80);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="navi">
	<span class="a" name="back">批量应用管理</span>&gt;&gt;
	<span name="title">Xxx批量应用节点</span>&gt;&gt;
	<span>任务监控</span>
</div>
<div class="head">
	<span>查找：</span>
	<input type="text" name="key" placeholder="请输入任务名" />
	<button name="find">查找</button>
	<button name="refresh">刷新</button>
	<div class="clear"></div>
</div>
<div class="main">
	<div class="grid"></div>
	<div class="clear"></div>
</div>